<template>
  <div style="font-size: 9px;">
    <div>食品名称：{{ CookieTemplateList.foodName}}</div>
    <div v-if="showIngredient">配料表：{{ CookieTemplateList.ingredient }}</div>
    <div style="">
      <span v-if="showNetContent" style="display: inline-block;width: 40%;">净含量：{{ CookieTemplateList.netContent}}</span>
      <span style="display: inline-block;width: 60%;">{{ productDate }}</span>
    </div>
    <div>储藏方式：{{ CookieTemplateList.storageConditions}}</div>
    <div style="">
      <span style="display: inline-block;width: 36%;">产品类别：{{ CookieTemplateList.productCategory}}</span>
      <span style="display: inline-block;width: 30%;">加工方式：{{ CookieTemplateList.processingMode}}</span>
      <span style="display: inline-block;width: 30%;">保质期：{{ CookieTemplateList.term}}</span>
    </div>
    <div style="margin: 1px 2px 1px 0;">{{ organization }}</div>
    
    <div style="position: relative;">
      <div style="width: 60%;display: inline-block; vertical-align: top;">
        <div style="margin: 1px 2px 1px 0;">地址：{{ getWarehouseAddress() }}</div>
        <div>联系方式：{{ CookieTemplateList.contactInformation}}</div>
        <div v-if="showLicence">{{ licence }}</div>
        <div v-if="showStandard">产品执行标准：{{ CookieTemplateList.executiveStandards}}</div>
        <div>致敏物提示：{{ CookieTemplateList.sensitizerTips}}</div>
        <div>食用方法：{{ CookieTemplateList.edibleMethods}}</div>
      </div>

      <div style="width: 36%;position: absolute;top: 0;right: 0;" v-if="showTable">
        <table cellspacing="0" style="border-collapse: collapse;border: solid 1px #000;">
          <tr style="">
            <td :colspan="3" style="border: solid 1px #000;font-size: 6px;width: 100%;">营养成分表</td>
          </tr>
          <tr style="">
            <td style="border: solid 1px #000;padding: 0 3px;font-size: 6px;width: 30%;">项目</td>
            <td style="border: solid 1px #000;padding: 0 3px;font-size: 6px;width: 47%;">每100克（g）</td>
            <td style="border: solid 1px #000;padding: 0 3px;font-size: 6px;width: 23%;">NRV%</td>
          </tr>
          <tr v-for="(Nutrients,Nutindex) in CookieTemplateList.goodsSkuProductionNutrientsList" :key="Nutindex" style="">
            <td style="border-left: solid 1px #000;padding: 0 3px;font-size: 6px;width: 30%;">{{ Nutrients.item }}</td>
            <td style="font-size: 6px;width: 47%;">{{ Nutrients.content }}</td>
            <td style="border-right: solid 1px #000;font-size: 6px;width: 23%;">{{ Nutrients.percentage }}</td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    CookieTemplateList: {
      required: true,
    },
    orderDetail: {
      required: true,
    }
  },
  data() {
    return {
      getNowTime: '',
    };
  },
  created() {
    this.getDate()
  },
  mounted() {
  },
  computed: {
    organization() {
      const label = (this.orderDetail.printingAlias && this.orderDetail.printingAlias.salesOrganizationName) ||
            '生产商'
      return `${label}：${this.CookieTemplateList.salesOrganizationName}`
    },
    licence() {
      const label = (this.orderDetail.printingAlias && this.orderDetail.printingAlias.licence) ||
            '食品生产许可证编号'
      return `${label}：${this.CookieTemplateList.licence}`
    },
    productDate() {
      const label = (this.orderDetail.printingAlias && this.orderDetail.printingAlias.productionDateName) || '生产日期'
      return `${label}：${this.dayjs().format('YYYY-MM-DD')}`
    },
    showIngredient() {
      return !!this.CookieTemplateList.ingredient
    },
    showNetContent() {
      return !!this.CookieTemplateList.netContent
    },
    showLicence() {
      return !!this.CookieTemplateList.licence
    },
    showStandard() {
      return this.CookieTemplateList.executiveStandards
    },
    showTable() {
      return this.CookieTemplateList.goodsSkuProductionNutrientsList &&
              this.CookieTemplateList.goodsSkuProductionNutrientsList.length
    }
  },
  methods: {
    getDate() {
      let nowYear = new Date().getFullYear();
      let nowMonth = (new Date().getMonth() + 1) < 10 ? "0" + (new Date().getMonth() + 1) : (new Date().getMonth() +
        1);
      let nowDate = new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate();
      let nowTime = nowYear + '年' + nowMonth + '月' + nowDate + '日';
      this.getNowTime = nowTime;
    },
    getWarehouseAddress(){
      if (JSON.parse(localStorage.getItem("saber-areaId")).content == 14) {
        return '湖南省长沙市芙蓉区隆平高科技园雄天路118号6号栋1楼101室'
      }else if(JSON.parse(localStorage.getItem("saber-areaId")).content == 9) {
        return '佛山市禅城区祖庙街道镇安东路西侧十字涌工业区A117'
      }else {
        return (this.orderDetail.printingAlias && this.orderDetail.printingAlias.warehouseAddress) ||
          this.CookieTemplateList.warehouseAddress
      }
    }
  },
};
</script>

<style lang='scss'>
</style>
